<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="paperList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="试卷编号" align="center" prop="paperId"/>
      <el-table-column label="阶段名称" align="center" prop="stageName"/>
      <el-table-column label="试卷名称" align="center" prop="paperName"/>
      <el-table-column label="考试者" align="center" prop="createBy"/>
      <el-table-column label="总分" align="center" prop="totalScore"/>


      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="showDetail(scope.row)"
            v-hasPermi="['online:history:show']"
          >查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
import {listStuDetail,getPaper, delQues, addPaper, updateQues,getCount } from "@/api/store/detail";
import {delStage, getStage} from "@/api/stage/stagelist";
import axios from "axios";

export default {
  name: "Ques",
  dicts: ['sys_normal_disable'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      userId:undefined,
      //试卷Id
      paperId:undefined,
      paperName:undefined,
      totalTime:undefined,
      totalMark:undefined,
      passMark:undefined,
      singleCount:0,
      totalScore:undefined,
      storeOptions:[],
      storeName:undefined,
      storeId:undefined,

      // 总条数
      total: 0,
      // 岗位表格数据
      paperList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        paperId:undefined,
        paperName:undefined,
        totalTime:undefined,
        totalMark:undefined,
        passMark:undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        quesName: [
          { required: true, message: "题库名称不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },

  computed: {
    addtotal() {
      return 100;
    },
  },


  methods: {
    showDetail(row){
      this.$router.push("/his/"+row.userId+"/"+row.paperId)
    },

    /** 显示所有 */
    getList() {
      this.loading = true;
      listStuDetail(this.queryParams).then((response) => {
        this.paperList = response.rows;
        this.total = response.total;
        this.loading = false;
        });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        quesId: undefined,
        storeId:undefined,
        quesName: undefined,
        quesHard:undefined,
        quesType:undefined,
        selContA:'',
        selContB:'',
        selContC:'',
        selContD:'',
        remark: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.storeId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      getPaper().then(response => {
        this.storeOptions = response.stores;
        this.singleCount = response.singleCount;
        this.judgeCount = response.judgeCount;
        this.manyCount = response.manyCount;
        this.open = true;
        this.title = "添加试卷";
      });
      this.reset();
    },

    showCounts(){

    },


    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const quesId = row.quesId || this.ids
      getQues(quesId).then(response => {
        this.storeOptions = response.stores;
        this.form = response.data;
        this.open = true;
        this.title = "修改题目";
        this.typeSelect = response.data.quesType
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.quesId != undefined) {
            updateQues(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPaper(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const quesIds = row.quesId || this.ids;
      this.$modal.confirm('是否确认删除题目编号为"' + quesIds + '"的数据项？').then(function() {
        return delQues(quesIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/post/export', {
        ...this.queryParams
      }, `post_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style>
.diaolog .el-table .el-table__header-wrapper thead th,
.diaolog .el-table .el-table__fixed-header-wrapper thead th {
  display: none;
}
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
